//
//  HRFunChatRootViewController.m
//  Hear
//
//  Created by mac on 2017/11/24.
//  Copyright © 2017年 mac. All rights reserved.
//

#import "HRFunChatRootViewController.h"
#import "HRFunChatFromSelfViewController.h"
#import "HRFunChatViewController.h"
#import "YBPopupMenu.h"
#import "HRRecordAudioViewController.h"
#import "HRTopicListViewController.h"

@interface HRFunChatRootViewController ()
@property (nonatomic, strong)UIImageView *backImageView;
@property(nonatomic, strong)HRFunChatFromSelfViewController *selfVC;
@property(nonatomic, strong)HRFunChatViewController *systemVC;
@property(nonatomic, strong)UIButton *tempButton;
@property(nonatomic, strong)UIButton *searchButton;

@end

@implementation HRFunChatRootViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
    [self setupView];
}
- (void)setupView{

    self.backImageView = [UIImageView new];
    self.backImageView.image = [UIImage imageNamed:@"FunChat_背景"];
    self.backImageView.userInteractionEnabled = YES;
    self.backImageView.contentMode = UIViewContentModeScaleAspectFill;
    [self.view addSubview:self.backImageView];
    self.backImageView.height -= kTabBarHeight;
    
    WeakSelf
    [self.backImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.equalTo(weakSelf.view);
        make.bottom.equalTo(weakSelf.view).offset(-kTabBarHeight);
    }];
    
    UIButton *fromSelfButton = [UIButton buttonWithType:0];
    fromSelfButton.frame = CGRectMake(20,kStatusBarHeight*2, 100, 30);
    [fromSelfButton setTitle:@"自创话题" forState:0];
    [fromSelfButton setTitleColor:[UIColor whiteColor] forState:0];
    fromSelfButton.titleLabel.font = CustomUIFont(17);
    [self.view addSubview:fromSelfButton];
    fromSelfButton.backgroundColor = BlueColor;
    fromSelfButton.layer.cornerRadius = fromSelfButton.width/12;
    fromSelfButton.clipsToBounds = YES;
    [fromSelfButton addTarget:self action:@selector(cutVCClick:) forControlEvents:UIControlEventTouchUpInside];
    self.tempButton = fromSelfButton;
    fromSelfButton.tag = 0;
    
    UIButton *fromSysButton = [UIButton buttonWithType:0];
    fromSysButton.frame = CGRectMake(fromSelfButton.right,fromSelfButton.top, fromSelfButton.width, fromSelfButton.height);
    [fromSysButton setTitle:@"官方话题" forState:0];
    [fromSysButton setTitleColor:[UIColor whiteColor] forState:0];
    fromSysButton.titleLabel.font = CustomUIFont(17);
    [self.view addSubview:fromSysButton];
    [fromSysButton addTarget:self action:@selector(cutVCClick:) forControlEvents:UIControlEventTouchUpInside];
    fromSysButton.layer.cornerRadius = fromSysButton.width/12;
    fromSysButton.clipsToBounds = YES;
    fromSysButton.tag = 1;
    
    UIButton *searchButton = [UIButton buttonWithType:0];
    searchButton.frame = CGRectMake(kFullWidth-50, fromSysButton.top, 30, 30);
    [searchButton setImage:[UIImage imageNamed:@"加号"] forState:0];
    [searchButton addTarget:self action:@selector(searchButtonClick) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:(self.searchButton=searchButton)];

    
    HRFunChatFromSelfViewController *selfVC = [HRFunChatFromSelfViewController new];
    selfVC.view.frame = CGRectMake(0, fromSysButton.bottom+kStatusBarHeight, self.view.width, self.view.height-fromSysButton.bottom-kTabBarHeight-kStatusBarHeight);
    DDLog(@"%f",selfVC.view.height);

    HRFunChatViewController *systemVC = [HRFunChatViewController new];
    systemVC.view.frame = selfVC.view.frame;
    systemVC.view.hidden = YES;
    [self.view addSubview:selfVC.view];
    [self.view addSubview:systemVC.view];
    [self addChildViewController:(self.selfVC=selfVC)];
    [self addChildViewController:(self.systemVC=systemVC)];
    
    
}

- (void)searchButtonClick{
    
    HRRecordAudioViewController *VC = [HRRecordAudioViewController new];
    VC.title = @"创建话题";
    VC.isFromTopic = YES;
    VC.soundRemendText = @"请输入你要创建的话题内容";
    [self.navigationController pushViewController:VC animated:YES];
//    [YBPopupMenu showRelyOnView:self.searchButton titles:@[@"我的话题",@"发起话题"] icons:@[@"我的话题",@"发起话题"] menuWidth:140.f textColor:FirstTextColor delegate:self];
}

#pragma -mark- YBPopupMenuDelegate
- (void)ybPopupMenuDidSelectedAtIndex:(NSInteger)index ybPopupMenu:(YBPopupMenu *)ybPopupMenu{
    if (index == 0){
        HRTopicListViewController *VC = [HRTopicListViewController new];
        VC.title = @"我的话题";
        [self.navigationController pushViewController:VC animated:YES];
    }else if (index == 1){
        HRRecordAudioViewController *VC = [HRRecordAudioViewController new];
        VC.title = @"创建话题";
        VC.isFromTopic = YES;
        VC.soundRemendText = @"请输入你要创建的话题内容";
        [self.navigationController pushViewController:VC animated:YES];
    }
}

- (void)cutVCClick:(UIButton *)button{
    self.tempButton.backgroundColor = [UIColor clearColor];
    self.tempButton = button;
    self.tempButton.backgroundColor = BlueColor;
    if (button.tag == 0){
        self.searchButton.hidden = NO;
        self.systemVC.view.hidden = YES;
        self.selfVC.view.hidden = NO;
        [self.selfVC starAnimationWithTableView:self.selfVC.tableView];
    }else{
        self.searchButton.hidden = YES;
        self.systemVC.view.hidden = NO;
        self.selfVC.view.hidden = YES;
        [self.systemVC starAnimationWithTableView:self.systemVC.tableView];
    }
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:YES];
}

-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [self.navigationController setNavigationBarHidden:NO];
}

-(UIStatusBarStyle)preferredStatusBarStyle{
    return UIStatusBarStyleLightContent;
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
